package com.weipai.springboot.module.mapper;

import com.weipai.springboot.model.Shop;
import com.weipai.springboot.model.api.Response;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

import java.util.List;
import java.util.Map;

/**
 * 店铺
 */
public interface ShopMapper{

    //通过id查询店铺的详情
    Shop getShopById(String shopId);

    Map<String,Object> getShopByIdAndMap(String shopId);

    //查询未删除/已删除的数据
    List<Shop> selectAllByShopDel(@Param("del") int del, @Param("search") String search,
                                  @Param("sort") String sort, @Param("way") String way,
                                  @Param("applicantStatus") Integer applicantStatus);

    //批量删除
    int batchDeleteById(String[] id);

    //绑定手机号
    @Update("update c_shop set applicant_mobile=#{mobile}, update_time=date_format(now(), '%Y-%m-%d %H:%i:%s') " +
            "where shop_id=#{id}")
    int updateMobile(@Param("id") String shopId, @Param("mobile") String mobile);

    //修改店铺邮箱
    @Update("update c_shop set applicant_email=#{email}, update_time=date_format(now(), '%Y-%m-%d %H:%i:%s') " +
            "where shop_id=#{id}")
    int updateEmail(@Param("id") String shopId, @Param("email") String email);

    //物理删除  shop信息
    int deleteByPrimaryKey(String shopId);

    int insert(Shop record);

    int insertSelective(Shop record);

    Shop selectByPrimaryKey(String shopId);

    //* 更新  店铺信息详情
    int updateByPrimaryKeySelective(Shop record);

    int updateByPrimaryKey(Shop record);

    //查询店铺信息：关注人数、店铺名称、logo
    Map<String,Object> getShopHeaderInfoByShopId(String shopId);


    //通过用户id查询店铺
    Shop getShopByCustomerId(String customerId);


    List<Map<String,Object>> getShopStatement(@Param("start") int start, @Param("end") Integer end);

    int getShopStatementAmount();

    //更改客户的未结算值和已结算值
    @Update("update c_shop set no_withdrawal=#{noWithdrawal}, have_withdrawal=#{haveWithdrawal} " +
            "where shop_id=#{id}")
    int changeWithdrawal(@Param("id") String shopId, 
                              @Param("noWithdrawal") String noWithdrawal, 
                              @Param("haveWithdrawal") String haveWithdrawal);


    @Update("update c_shop set no_withdrawal=no_withdrawal + #{allProfit} where shop_id = #{shopId}")
    int updateNoWithdrawal(@Param("shopId") String shopId, @Param("allProfit") int allProfit);


    //对外接口  返回供应商信息
    List<Map<String,Object>> getShopMessage();
}